<template>
  <div>
    <el-card
      shadow="never"
      :body-style="{ padding: '0px' }"
      :page-size="pageSize"
      :total="rows"
      :current-page="pageNo"
      @current-change="currentChangeHandle"
    >
      <el-table v-loading="dataListLoading" :data="dataList" stripe>
        <el-table-column
          prop="versionName"
          min-width="80px"
          :label="$t('appstore.application.appVersion')"
        />
        <el-table-column
          prop="versionCode"
          min-width="80px"
          :label="$t('appstore.application.appVersionCode')"
        />
        <el-table-column
          prop="revision"
          min-width="300px"
          :label="$t('appstore.application.revision')"
        >
          <template v-slot="scope">
            <div class="justify-between" style="display: flex">
              <div class="html-container">
                <div
                  style="padding: 12px"
                  v-html="scope.row.appLanguageInfoList[0].revision"
                />
              </div>
              <el-button type="text" class="mx-2" @click="moreLanguage(scope.row)">
                {{ $t("appstore.application.other_lang") }}
              </el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <!-- <el-pagination
      :current-page="pageNo"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="rows"
      layout="total, sizes, prev, pager, next, jumper"
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
    /> -->
    <el-dialog
      v-model="languageVisible"
      :title="currentVersion.versionName"
      width="680px"
    >
      <el-table
        :data="currentVersion.appLanguageInfoList"
        border
        style="width: 100%"
        stripe
      >
        <el-table-column prop="language" width="180px" :label="$t('common.language')">
          <template v-slot="{ row }">
            {{ $t("language_list." + row.language) }}
          </template>
        </el-table-column>
        <el-table-column prop="revision" :label="$t('appstore.application.revision')">
          <template v-slot="scope">
            <div class="html-container">
              <div style="padding: 12px" v-html="scope.row.revision" />
            </div>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>
<script>
import { appRevisionList } from "@/api/developer-app";
import { HTMLDecode } from "@/utils";

export default {
  data() {
    return {
      languageVisible: false,
      currentVersion: "",
      dataList: [],
      appId: 0,
      pageNo: 1,
      pageSize: 10,
      rows: 0,
      dataListLoading: false,
    };
  },
  methods: {
    moreLanguage(currentVersion) {
      this.currentVersion = currentVersion;
      this.languageVisible = true;
    },
    init(id) {
      this.visible = true;
      this.appId = id;
      this.getAppRevisionList();
    },
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageNo = 1;
      this.getAppRevisionList();
    },
    currentChangeHandle(val) {
      this.pageNo = val;
      this.getAppRevisionList();
    },
    getAppRevisionList() {
      const params = {
        pageNo: this.pageNo,
        pageSize: this.pageSize,
      };
      this.dataListLoading = true;
      appRevisionList(this.appId, params)
        .then((data) => {
          this.dataList = data.data;
          if (this.dataList.length > 0) {
            for (var i = 0, l = this.dataList.length; i < l; i++) {
              this.dataList[i].revision = HTMLDecode(this.dataList[i].revision);
            }
          }

          this.rows = data.rows;
          this.dataListLoading = false;
        })
        .catch((e) => {
          this.dataListLoading = false;
          this.$confirmError(e);
          console.log(`err:${JSON.stringify(e)}`);
        });
    },
  },
};
</script>
<style lang="scss" scoped>
.html-container {
  ::v-deep a {
    color: #3f9eff;
    text-decoration: underline;
  }
  ::v-deep blockquote {
    border-left: solid 4px #eeeeee;
    padding-left: 16px;
  }
}
</style>
